%by clq
%2021/6/12
function[i_RP,profits_RP]=round_robin_pref(j_all,pref)
global I J
%j_all is the given order of patient types
addpath functions;
n=size(j_all,2);
S=zeros(I,J);

%Step1:decide the preference randomly, and then find the optimal slot for each patient
j=0;k=0;

for i=1:n
    pref_temp=pref(i);
    if pref_temp==1
       j=j+1;
       i_RP(i)=mod(j-1,I/2)+1;
    else
       k=k+1;
       i_RP(i)=mod(k-1,I/2)+5;
    end
end
%Step2:find the profit after each patient is assigned
for i=1:n
    j=j_all(i);
    S(i_RP(i),j)=S(i_RP(i),j)+1;
       Q = findQ(S); 
       R = findR(Q);
       profits_RP(i)=function_fQR(Q,R);
end
